package edu.ptu.springboot04.controller;

import edu.ptu.springboot04.common.controller.JsonResponse;
import edu.ptu.springboot04.domain.query.OrderQuery;
import edu.ptu.springboot04.service.IOrderService;
import edu.ptu.springboot04.utils.JWTUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @BelongsProject: springboot04
 * @BelongsPackage: edu.ptu.springboot04.controller
 * @Author: HYJ
 * @CreateTime: 2025-03-21  21:14
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    //1.根据购物车ids查询所有的商品列表
    //2.根据http获取userId,生成order表
    //3.根据userId查询到的商品列表生成orderDtl表
    //4.删除购物车
    @Resource
    private IOrderService orderService;

    //添加订单
    @PostMapping("/add")
    public JsonResponse addOrder(@RequestBody OrderQuery orderQuery, HttpServletRequest request) {
        //根据orderQuery和request中的userId生成订单
        return orderService.insertOrders(orderQuery, JWTUtil.getUserId(request)) > 0L ? JsonResponse.success() :
                JsonResponse.fail();
    }

}
